package bobaini.com.dead_exchange;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * ClassName: Product
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/25-22:36:00
 * Description:
 */
public class Product {
    private static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        /**
         * 声明交换机
         */
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);

        /**
         * 设置消息的TTL时间(存活时间), 消息只存活10秒, 若未被消费,则进入死信队列
         */
//        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("5000").build();

        /**
         * zhangsan就是RountingKey
         */
        for (int i = 1; i < 10; i++) {
            String message = "info" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan", null, message.getBytes());
            System.out.println("生产者发送消息:" + message);
        }

    }
}
